import { Global, Module } from '@nestjs/common';
import { MongodbService } from './mongodb.service';
import { MongooseModule } from '@nestjs/mongoose';
import { ConfigureModule, ConfigureService } from '@app/configure';
import { DeviceData, DeviceDataSchema } from './schemas/deviceData';
import { RawData, RawDataSchema } from './schemas/rawData';
import { OrderPowerData, OrderPowerDataSchema } from './schemas/orderPowerData';


@Global()
@Module({
  imports : [
    MongooseModule.forRootAsync({
      imports : [ConfigureModule],
      inject : [ConfigureService],
      useFactory : (config:ConfigureService) => {
        return {
          ...config.get('mongodb'),
        }
      }
    }),

    MongooseModule.forFeature([
      {name : DeviceData.name, schema : DeviceDataSchema},
      {name : RawData.name, schema : RawDataSchema},
      {name : OrderPowerData.name, schema : OrderPowerDataSchema},
    ])
  ],
  providers: [MongodbService],
  exports: [MongodbService],
})
export class MongodbModule {}
